package self.hoy.demo.rabbitmq.route;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import self.hoy.demo.rabbitmq.Constant;
import self.hoy.demo.rabbitmq.util.ConnectionUtils;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author hyh
 * @date 2020/6/7
 */
public class Send implements Constant {
    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = ConnectionUtils.getConnection();
        Channel channel = connection.createChannel();
        channel.exchangeDeclare(DIRECT_EXCHANGE_NAME, TYPE_DIRECT);//direct
        String msg = "this is direct message " + System.currentTimeMillis();
//        channel.queueDeclare()
        String routingKey = "debug";
        channel.basicPublish(DIRECT_EXCHANGE_NAME, routingKey, null, msg.getBytes());
        System.out.println("sending : " + msg);
        channel.close();
        connection.close();
    }
}
